<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //使用构造函数创建对象（也叫构造器）

        //创建一个无参的构造函数
        function Student(){
            this.name='高伟杰'
            this.age=21;
            this.hobby=function(){
                console.log('吃饭');
            }
            this.show=function(){
                console.log('我的名字是'+this.name+"我的年龄是"+this.age)
            }
        }
        //调用自定义对象
        var stu = new Student();
        console.log(stu.name);
        console.log(stu.age);
        stu.hobby();
        stu.show();


        //创建一个带参的构造函数
        function Dog(h,l,names){
            this.height=h
            this.name=names
            this.old=l
            this.can=function(){
                console.log('我是一只狗我的名字是'+this.name+'我今年'+this.old+'岁了'+'我的体重是'+this.height+'我可以看家')
            }
        }
        // var dog = new Dog;
        // console.log(dog.old);
        // console.log(dog.name);
        // console.log(dog.height);
        // dog.can();
        var dog = new Dog('20kg',99,'听泉')
        console.log(dog.name)
        console.log(dog.old)
        console.log(dog.height)
        dog.can();
        
    </script>
</head>
<body>
    
</body>
</html>